from django.contrib import admin
from .models import Menus, ExtendSalesman
from .models import UserType


class UserTypeAdmin(admin.ModelAdmin):
    list_display = ("account_type",)


class ExtendSalesmanAdmin(admin.ModelAdmin):
    list_display = ("user_type_desc", "sales_desc")

    def user_type_desc(self, model):
        return model.user_type.get_account_type_display()

    def sales_desc(self, model):
        return model.sales.account if model.sales.account else model.sales.id

    user_type_desc.short_description = "管理员类型"
    sales_desc.short_description = "用户"


class MenusAdmin(admin.ModelAdmin):
    list_display = ("menu", "url", "parent_menus_name", "open_option", "show_status")

    def parent_menus_name(self, model):
        return model.parent_menus.menu if model.parent_menus else ""

    def open_option(self, model):
        return model.open_menus.menu if model.open_menus else ""

    parent_menus_name.short_description = "父菜单"
    open_option.short_description = "展开菜单"


admin.site.register(ExtendSalesman, ExtendSalesmanAdmin)
admin.site.register(Menus, MenusAdmin)
admin.site.register(UserType, UserTypeAdmin)
